package com.ll.gulimall.cart.config;

import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Component;

import java.util.concurrent.Executors;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

@Component
public class ThreadConfig {

    @Bean
    public ThreadPoolExecutor getThreadPoolExecutor(CartConfig cartConfig) {

        ThreadPoolExecutor poolExecutor = new ThreadPoolExecutor(cartConfig.getCore(), cartConfig.getMax(), cartConfig.getTime()
                , TimeUnit.SECONDS, new LinkedBlockingQueue<>(10000),
                Executors.defaultThreadFactory(), new ThreadPoolExecutor.AbortPolicy());
        return poolExecutor;
    }


}
